clear; clc;

Folder      =   'TableGraphs\\';
mkdir(Folder);

load('Results_HighVsLowForeignShares.mat');
% load('..//1_Baseline//2_MainResults//SOLUTION.mat','SOLUTION_Main');

%% Collect the Results
Mom         =   SubFun_ResultCell2Mom({SOLUTION_B_Low,SOLUTION_F_Low,SOLUTION_B_High,SOLUTION_F_High});
List_Model  =   {'Baseline, Low','FCD, Low','Baseline, High', 'FCD, High'};
List_SH     =   {'Eps_Eta_M_dom','Eps_Eta_Y_H','Eps_Eta_M_ext'};
for ii_SH=1:length(List_SH)
    SH          =   List_SH{ii_SH};
    TempData    =   [Mom.Stat.(SH)(1:3,:);...
                     bsxfun(@rdivide,Mom.Stat.(SH)(4:7,:),Mom.Stat.(SH)(1,:))];
    TempTable   =   array2table(TempData,'RowNames',Mom.StatNames,'VariableNames',List_Model);
    writetable(TempTable,[Folder,'SummaryTable.xlsx'],'WriteRowNames',true,'Sheet',SH);
end

%% Decomposition
Step_2_Decomposition(SOLUTION_B_Low,['TableGraphs//B_Low//Decomposition//']);
Step_2_Decomposition(SOLUTION_F_Low,['TableGraphs//F_Low//Decomposition//']);

Step_2_Decomposition(SOLUTION_B_High,['TableGraphs//B_High//Decomposition//']);
Step_2_Decomposition(SOLUTION_F_High,['TableGraphs//F_High//Decomposition//']);


%% Fake News Study
T               =   50;
% SOL             =   SOLUTION_F_Low;
SOL             =   SOLUTION_B_Low;
FakeNewsIRF     =   zeros(size(SOL.SS.AggStat,1),T);

FakeNewsIRF(:,1)=   SOL.EquJac.HH.dE(SOL.MODEL.EquBlock.HH.LocIdx.Out.AggStat,1);

for tt=2:T
    Temp            =   SOL.EquJac.HH.ValFunp* ...
                        (SOL.EquJac.HH.ValFunp(SOL.MODEL.EquBlock.HH.LocIdx.Out.ValFun,:)^(tt-1))* ....
                        SOL.EquJac.HH.dE(SOL.MODEL.EquBlock.HH.LocIdx.Out.ValFun);
    FakeNewsIRF(:,tt)=  Temp(SOL.MODEL.EquBlock.HH.LocIdx.Out.AggStat);
end

plot(FakeNewsIRF(1:2,:)');